package main

import (
	"errors"
	"iot-base/common/logger"
	"net"
	"time"
)

func saveFile() (bool, error) {
	conn, ecc := net.DialTimeout("tcp", "127.0.0.1:37125", 2*time.Second)
	if ecc != nil {
		return false, ecc
	}
	cmd := `{"REQ": "SaveFile", "Type":"DevList"}` + "\r\n"
	_, err := conn.Write([]byte(cmd))
	logger.SLog.Info("cmd:save file", cmd)
	if err != nil {
		return false, err
	}
	req := ReadDt(conn)
	if req != nil {
		/*sreq := string(req)
		if strings.Contains(sreq, "Fail") {
			return false, errors.New(sreq)
		}*/
		logger.SLog.Info("cmd:save file req", string(req))
		return true, nil
	}
	return false, errors.New("get nil")
}
